import cv2
import numpy as np
from PIL import Image

# 读取图片（确保还原后bg和滑块都是RGB/灰度格式）
bg = cv2.imread('captcha_imgs/restore/bg.jpg', 0)
slide = cv2.imread('captcha_imgs/slice.png', 0)

# 滑块取反（极验/风控有时需要反色）可视滑块用
# slide = 255 - slide

# 匹配
result = cv2.matchTemplate(bg, slide, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(result)
x = max_loc[0]
print("OpenCV检测到的滑块距离:", x)